<template>
  <div class="box">
    <h2>son1 子组件</h2>
    从vuex中获取到的值 <label>{{ count }}</label>
    <h3>{{ title }}</h3>
    <br>
    <button @click="addCount(1)">值 +1</button>
    <button @click="addCount(5)">值 +5</button>
    <button @click="addCount(10)">值 +10</button>
    <button @click="changeCountAsync">一秒后更改 为666</button>
    <hr>
    这是原数组： {{$store.state.list}}
    <hr>
    这是比5大的元素： {{$store.getters.filterList}}
    <hr>
    modules数据访问:<label>{{ $store.state.user.userInfo }}</label>
    <hr>
    modules访问getters:<label>{{ $store.getters["user/getUpperName"] }}</label>
    <hr>
    modules访问mutations:<button @click="changeUser">更改用户为碍事梨</button>
    <hr>
    modules访问actions:<button @click="changeUserAsync">一秒后用户为座山雕</button>
  </div>
</template>

<script>

export default {
  name: 'Son1',
  computed: {
    count () {
      return this.$store.state.count
    },
    title () {
      return this.$store.state.title
    }
  },
  methods: {
    addCount (num) {
      this.$store.commit('addCount', num)
    },
    changeCountAsync () {
      this.$store.dispatch('changeCountAsync', 666)
    },
    changeUser () {
      this.$store.commit('user/changeUser', {
        name: '碍事梨',
        age: 20
      })
    },
    changeUserAsync () {
      this.$store.dispatch('user/changeUserAsync', {
        name: '座山雕',
        age: 100
      })
    }
  }
}
</script>

<style lang="less">
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2{
  margin-top: 10px;
}
</style>
